package L7.L710;

/**
 * 删除k个数，使整数最小
 *
 * @author: luolidong
 * @create: 2021-07-10 18:53
 * @version: 1.0
 */
public class Demo1 {
    public int delete(int num, int k) {
        String s = String.valueOf(num);
        StringBuilder builder = new StringBuilder();
        int i = 0;
        while (i < s.length()) {
            if(k>0){
                if (i < s.length()-1&&s.charAt(i) > s.charAt(i + 1)||i+1==s.length()) {
                    k--;
                } else
                    builder.append(s.charAt(i));
            }else {
                builder.append(s.charAt(i));
            }
            i++;
        }
        return Integer.parseInt(builder.toString());
    }

    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        int delete = demo1.delete(36, 1);
        System.out.println("delete = " + delete);
    }
}
